function include(filename)
{
	var head = document.getElementsByTagName('head')[0]
	
	script = document.createElement('script')
	script.src = filename
	script.type = 'text/javascript'
	
	head.appendChild(script)
}

function trim(str, chars) 
{
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) 
{
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) 
{
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

//--------------------------
// On page finished loading
$(document).ready(function() {
//####### Fix for UTF8 encoding	
	jQuery.ajaxSetup ( {
		'beforeSend' : function(xhr) {
		xhr.overrideMimeType('text/html; charset=UTF-8');
		}
	});
//####### LOAD EXTERNAL JS
	include("scripts/tools.js")
	include("scripts/notes.js")
	include("scripts/categories.js")
	include("scripts/parser.js")
	include("scripts/articles.js")
	include("scripts/preferences.js")
});

function debug()
{
	$.ajax({
		type: "POST",
		url: "controllers/tags_controller.php",
		data: {action:'debug'},
		success: function(msg){
	    	$("#debug").html(msg)
		}
	});
}